package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsArticleMapper;
import com.qf.pojo.DtsArticle;
import com.qf.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 22:41
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private DtsArticleMapper dtsArticleMapper;

    /**
     * 公告显示
     * @param title
     * @param sort
     * @param order
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<DtsArticle> findListByQuery(String title, String sort, String order, Integer page, Integer limit) {
        return dtsArticleMapper.selectPage(new Page<DtsArticle>(page,limit),
                new QueryWrapper<DtsArticle>()
                .like(!StringUtils.isEmpty(title),"title",title)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }

    /**
     * 添加公告
     * @param dtsArticle
     * @return
     */
    @Override
    public DtsArticle create(DtsArticle dtsArticle) {
        dtsArticleMapper.insert(dtsArticle);
        return dtsArticle;
    }
    /**
     * 更新
     * @param dtsArticle
     * @return
     */
    @Override
    public DtsArticle update(DtsArticle dtsArticle) {
        dtsArticleMapper.updateById(dtsArticle);
        return dtsArticle;
    }

    /**
     * 删除
     * @param dtsArticle
     * @return
     */
    @Override
    public DtsArticle delete(DtsArticle dtsArticle) {
        dtsArticleMapper.deleteById(dtsArticle);
        return dtsArticle;
    }
}
